```
hi_u16 value;                      // 存温度的
    hi_u16 value1;                     // 存TDS的
    hi_u16 value2;                     // 存水压的
    const float thermistorR = 50000.0; // 温度传感器的分压电阻
    const float T0 = 298.15;           // 热敏电阻在25摄氏度下的温度，单位为开尔文
    const float B = 3950.0;            // 热敏电阻的B值
    float Vntc, Rntc;                  // 热敏电阻的电压、电阻
    float Vtemp;
    int average = 0, sum = 0;
    float date[5];         // 存储数据
    char strArray[20][33]; // 存储转换后的字符串数组包括终止符'\0'

    while (1)
    {
        // 1.测水流量
        printf("-----------start---------\n");
        hi_gpio_register_isr_function(HI_GPIO_IDX_4, HI_INT_TYPE_EDGE, HI_GPIO_EDGE_RISE_LEVEL_HIGH, Func, NULL); // 上升沿中断
        f = (float)num / p;                                                                                       // 用了多少升水
        printf("num:%d\n", num);
        printf("water : %fL\n", f + history_f); // 打印水流量
        date[0] = f + history_f;
        usleep(100000);
        // 2.测温度
        if (hi_adc_read(HI_ADC_CHANNEL_0, &value, HI_ADC_EQU_MODEL_8, HI_ADC_CUR_BAIS_DEFAULT, 0) != HI_ERR_SUCCESS) // 读取引脚的模拟信号
        {
            printf("ADC read error!\n");
        }
        else
        {
            Vntc = ((float)value * 4 * 1.8) / 4096.0; // 将模拟量转换成实际电压值
            // Vntc = Vntc + 1;
            Vtemp = Vntc + 0.1;
            Rntc = (thermistorR * Vtemp) / (5.0 - Vtemp); // 分压公式
            temperature = (1 / (MYLOG((double)Rntc / (double)thermistorR) / B + (1 / T0))) - 273.15; // 热敏电阻计算温度的固定公式
            printf("temp = %.2f\n", temperature);
            date[1] = temperature;
            usleep(100000);
        }

        // 3.测TDS
        if (hi_adc_read(HI_ADC_CHANNEL_4, &value1, HI_ADC_EQU_MODEL_4, HI_ADC_CUR_BAIS_DEFAULT, 0) != HI_ERR_SUCCESS)
        {
            printf("TDS read error!\n");
        }
        else
        {
            // printf("value1:%d\n", value1);
            analogBuffer[analogBufferIndex] = (value1 * 4 * 1.8) / 4096; // 转换成电压
            // averageVoltage = ((float)value1 * 4 * 1.8) / 4096.0;
            // printf("analogBuffer[%d]:%f\n", analogBufferIndex, analogBuffer[analogBufferIndex]);
            analogBufferIndex++;
            if (analogBufferIndex == SCOUNT)
            {
                analogBufferIndex = 0;
            }
            for (copyIndex = 0; copyIndex < SCOUNT; copyIndex++)
            {
                analogBufferTemp[copyIndex] = analogBuffer[copyIndex];
            }
            averageVoltage = getMedianNum(analogBufferTemp, SCOUNT); // 通过中值滤波算法读取更稳定的模拟值，并转换为电压值
            // printf("TDS_averageV1:%.2f\n", ((float)value1 * 4 * 1.8) / 4096.0);
            // averageVoltage = ((float)value1 * 4 * 1.8) / 4096.0;
            // printf("TDS_averageV2:%f\n", averageVoltage);
            tdsValue = (133.42 * averageVoltage * averageVoltage * averageVoltage - 255.86 * averageVoltage * averageVoltage + 857.39 * averageVoltage) * 1.18;
            // ECvalue25  =  ecvalue / (1.0+0.02*(temperature-25.0));
            tdsValue = tdsValue / (1.0 + 0.02 * (22 - 25.0));
            tdsValue = tdsValue / 2;
            printf("TDS:%.2fppm\n", tdsValue);
            date[2] = tdsValue;
            usleep(100000);
        }

        // 4.测水压
        if (hi_adc_read(HI_ADC_CHANNEL_2, &value2, HI_ADC_EQU_MODEL_4, HI_ADC_CUR_BAIS_DEFAULT, 0) != HI_ERR_SUCCESS)
        {
            printf("Hydraulic read error!\n");
        }
        else
        {
            Hydraulic = (value2 * 4 * 1.8) / 4096; // 转换成电压
            // printf("value2:%f", Hydraulic);
            printf("Hydraulic:%.2fKpa\n", (200 * Hydraulic));
            date[3] = 200 * Hydraulic;
            usleep(100000);
        }

        for (int i = 0; i < 4; i++)
        {
            sprintf(strArray[i], "%f", date[i]);
        }

        printf("-----------end---------\n");
        usleep(1000000);

    }
```

